package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.AlbumInfoService;
import com.atguigu.tingshu.common.anno.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.query.album.AlbumInfoQuery;
import com.atguigu.tingshu.vo.album.AlbumInfoVo;
import com.atguigu.tingshu.vo.album.AlbumListVo;
import com.atguigu.tingshu.vo.album.AlbumStatVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "专辑管理")
@RestController
@RequestMapping("api/album/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class AlbumInfoApiController {

    @Autowired
    private AlbumInfoService albumInfoService;



    @GuiGuLogin
    @Operation(summary = "查询用户所有的分类列表")
    @GetMapping("findUserAllAlbumList")
    public Result<List<AlbumInfo>> findUserAllAlbumList(){
        List<AlbumInfo> albumInfoList = albumInfoService.findUserAllAlbumList();
        return Result.ok(albumInfoList);
    }


    @GuiGuLogin
    @Operation(summary = "新增专辑接口")
    @PostMapping("/saveAlbumInfo")
    public Result saveAlbumInfo(@RequestBody @Validated AlbumInfoVo albumInfoVo) {
        albumInfoService.saveAlbumInfo(albumInfoVo);
        return Result.ok(null);
    }

    @Operation(summary = "查询当前用户专辑分页列表")
    @PostMapping("findUserAlbumPage/{page}/{limit}")
    public Result<IPage<AlbumListVo>> findUserAlbumPage(@PathVariable("page") Long pageNum,
                                                        @PathVariable("limit") Long pageSize,
                                                        @RequestBody AlbumInfoQuery albumInfoQuery) {
        IPage<AlbumListVo> albumListVoIPage = albumInfoService.findUserAlbumPage(pageNum, pageSize, albumInfoQuery);
        return Result.ok(albumListVoIPage);
    }

    @Operation(summary = "根据id删除专辑")
    @DeleteMapping("/removeAlbumInfo/{id}")
    public Result removeAlbumInfo(@PathVariable Long id) {
        albumInfoService.removeAlbumInfo(id);
        return Result.ok(null);
    }


    @Operation(summary = "根据id查询专辑用于回显")
    @GetMapping("/getAlbumInfo/{id}")
    public Result<AlbumInfo> getAlbumInfo(@PathVariable Long id) {
        AlbumInfo albumInfo = albumInfoService.getAlbumInfo(id);
        return Result.ok(albumInfo);
    }

    @Operation(summary = "根据id修改专辑")
    @PutMapping("/updateAlbumInfo/{id}")
    public Result updateAlbumInfo(@PathVariable Long id,@RequestBody @Validated AlbumInfoVo albumInfoVo){
        albumInfoService.updateAlbumInfo(id,albumInfoVo);
        return Result.ok();
    }

    @Operation(summary = "获取专辑统计数据信息")
    @GetMapping("getAlbumStatVo/{albumId}")
    public Result<AlbumStatVo> getAlbumStatVo(@PathVariable(value = "albumId") Long albumId) {
        AlbumStatVo albumStatVo = albumInfoService.getAlbumStatVo(albumId);
        return Result.ok(albumStatVo);
    }


}

